package com.zut.edu.widget;

import android.content.Context;
import android.graphics.Color;
import android.widget.Toast;

import androidx.core.graphics.ColorUtils;

import com.zut.edu.bean.Chart;
import com.zut.edu.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import lecho.lib.hellocharts.listener.PieChartOnValueSelectListener;
import lecho.lib.hellocharts.model.PieChartData;
import lecho.lib.hellocharts.model.SliceValue;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.PieChartView;

/**
 * Created by kang on 2020/12/5.
 */

public class PieChartTool {


    public static void setChartViewData(final Context context, final List<Chart> heartList, PieChartView pieChart) {
        List<SliceValue> values = new ArrayList<SliceValue>();
        PieChartData pieChardata = new PieChartData();

        for(int i=0;i<heartList.size();i++){
            SliceValue sliceValue = new SliceValue((float) heartList.get(i).getData(), ChartUtils.pickColor());
            values.add(sliceValue);
        }

        pieChardata.setHasLabels(true);//显示表情
        pieChardata.setHasLabelsOnlyForSelected(false);//不用点击显示占的百分比
        pieChardata.setHasLabelsOutside(false);//占的百分比是否显示在饼图外面
        pieChardata.setHasCenterCircle(true);//是否是环形显示
        pieChardata.setValues(values);//填充数据
        pieChardata.setCenterCircleColor(Color.WHITE);//设置环形中间的颜色
        pieChardata.setCenterCircleScale(0.5f);//设置环形的大小级别
        pieChardata.setCenterText1("Hellocharts");//环形中间的文字
        pieChardata.setCenterText1Color(Color.BLACK);//文字颜色
        pieChardata.setCenterText1FontSize(14);//文字大小
        pieChardata.setCenterText2("Piechart");
        pieChardata.setCenterText2Color(Color.BLACK);
        pieChardata.setCenterText2FontSize(18);
        pieChart.setPieChartData(pieChardata);
        pieChart.setValueSelectionEnabled(true);//选择饼图某一块变大
        pieChart.setAlpha(0.9f);//设置透明度
        pieChart.setCircleFillRatio(1f);//设置饼图大小

        pieChart.setOnValueTouchListener(new PieChartOnValueSelectListener() {
            @Override
            public void onValueSelected(int i, SliceValue sliceValue) {
                switch (i){
                    case 0:Toast.makeText(context, heartList.get(0).getTime() + "：" +(int)sliceValue.getValue()+"次", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:Toast.makeText(context, heartList.get(1).getTime() + "：" +(int)sliceValue.getValue()+"次", Toast.LENGTH_SHORT).show();
                        break;
                    case 2:Toast.makeText(context, heartList.get(2).getTime() + "：" +(int)sliceValue.getValue()+"人", Toast.LENGTH_SHORT).show();
                        break;
                    case 3:Toast.makeText(context, heartList.get(3).getTime() + "：" +(int)sliceValue.getValue()+"人", Toast.LENGTH_SHORT).show();
                        break;
                    default:
                }

            }

            @Override
            public void onValueDeselected() {

            }
        });
    }


}
